// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: xguo, taekwon

#pragma once

#include <fstream>
#include <memory>
#include <optional>
#include <string>

#include <rapidjson/document.h>

class AuthKey {
 public:
  const std::optional<std::string> GetValue(const char* key) const;

  const std::string& owner() const { return owner_; }
  const std::string& key_name() const { return key_name_; }
  const std::string& access_key() const { return access_key_; }
  const std::string& secret_key() const { return secret_key_; }
  const std::string& generated() const { return generated_; }
  const std::string& generated_human() const { return generated_human_; }
  const std::string& email() const { return email_; }
  const std::string& password() const { return password_; }
  const std::string& token() const { return token_; }
  const std::string& account_type() const { return account_type_; }

  void set_owner(const std::string& owner) { owner_ = owner; }
  void set_key_name(const std::string& key_name) { key_name_ = key_name; }
  void set_access_key(const std::string& access_key) { access_key_ = access_key; }
  void set_secret_key(const std::string& secret_key) { secret_key_ = secret_key; }
  void set_generated(const std::string& generated) { generated_ = generated; }
  void set_generated_human(const std::string& generated_human) {
    generated_human_ = generated_human;
  }
  void set_email(const std::string& email) { email_ = email; }
  void set_password(const std::string& password) { password_ = password; }
  void set_token(const std::string& token) { token_ = token; }
  void set_account_type(const std::string& account_type) { account_type_ = account_type; }

  static AuthKey FromDocument(const rapidjson::Document& doc);
  static AuthKey FromFile(const std::string& filepath);

 private:
  rapidjson::Document document_;
  std::string owner_;
  std::string key_name_;
  std::string access_key_;
  std::string secret_key_;
  std::string generated_;
  std::string generated_human_;
  std::string email_;
  std::string password_;
  std::string token_;
  std::string account_type_;
};
